home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
101-125
/
118
/
empire
/
src
/
source.zoo
/
commands.d
< prev
next >
Wrap
Text File
|
1987-12-02
|
11KB
|
486 lines
#include:libraries/dos.g
#include:util.g
#empire.g
#empfunc.g
uint HelpColumn;
/*
* help - print one string as part of the three-column help listing.
*/
proc help(*char p)void:
uint i;
i := 25;
while p* ~= '\e' do
write(Chout; p*);
p := p + 1;
i := i - 1;
od;
HelpColumn := HelpColumn + 1;
if HelpColumn = 4 then
writeln(Chout;);
HelpColumn := 1;
else
while i ~= 0 do
i := i - 1;
write(Chout; ' ');
od;
fi;
corp;
/*
* cmd_help - print a list of currently implemented commands.
*/
proc cmd_help()void:
writeln(Chout; "Empire commands are:");
writeln(Chout;);
HelpColumn := 1;
help("accept - 2 BTU's");
help("assault - 2 BTU's");
help("attack - 2 BTU's");
help("board - 2 BTU's");
help("build - 2 BTU's");
help("buy - 2 BTU's");
help("bye");
help("census");
help("change");
help("checkpoint - 2 BTU's");
help("collect - 2 BTU's");
help("contract - 2 BTU's");
help("country");
help("declare - 2 BTU's");
help("defend - 2 BTU's");
help("deliver - 1 BTU");
help("designate - 1 BTU");
help("drop - 2 BTU's");
help("dump");
help("enlist - 2 BTU's");
help("fire - 2 BTU's");
help("fleet - 1 BTU");
help("fly - 2 BTU's");
help("forecast - 1 BTU");
help("grant - 1 BTU");
help("headlines");
help("ledger");
help("lend - 2 BTU's");
help("load - 2 BTU's");
help("lookout - 2 BTU's");
help("map - 1 BTU");
help("message");
help("mine - 2 BTU's");
help("move - 2 BTU's");
help("nation");
help("navigate - 2 BTU's");
help("newspaper");
help("power");
help("price - 2 BTU's");
help("radar - 2 BTU's");
help("read");
help("realm");
help("repay - 2 BTU's");
help("report - 2 BTU's");
help("route - 1 BTU");
help("ships");
help("spy - 1 BTU");
help("telegram");
help("tend - 2 BTU's");
help("torpedo - 2 BTU's");
help("unload - 2 BTU's");
help("update - 1 BTU");
help("weather");
if HelpColumn ~= 1 then
writeln(Chout;);
fi;
corp;
/*
* chargeCommand - try a command, if user can afford it. Add the BTU's back
* if the command returns 'false'.
*/
proc chargeCommand(proc()bool command; uint cost)void:
if ThisCountryNumber = DEITY then
pretend(command(), void);
else
if ThisCountry*.c_btu < cost then
writeln(Chout; "You don't have enough BTU's remaining!");
else
ThisCountry*.c_btu := ThisCountry*.c_btu - cost;
if not command() then
ThisCountry*.c_btu := ThisCountry*.c_btu + cost;
fi;
fi;
fi;
corp;
/*
* doCommand - attempt to execute the given single command.
*/
proc doCommand(uint cmd; *char command)void:
case cmd
incase 2:
chargeCommand(cmd_accept, 2);
incase 3:
chargeCommand(cmd_assault, 2);
incase 4:
chargeCommand(cmd_attack, 2);
incase 5:
chargeCommand(cmd_board, 2);
incase 6:
chargeCommand(cmd_build, 2);
incase 8:
QuietUpdate := false;
cmd_census();
incase 9:
cmd_change();
incase 10:
chargeCommand(cmd_checkpoint, 2);
incase 11:
chargeCommand(cmd_collect, 2);
incase 12:
cmd_help();
incase 13:
chargeCommand(cmd_contract, 2);
incase 14:
cmd_country();
incase 15:
cmd_fleet();
incase 16:
chargeCommand(cmd_defend, 2);
incase 17:
chargeCommand(cmd_deliver, 1);
incase 18:
chargeCommand(cmd_declare, 2);
incase 19:
chargeCommand(cmd_designate, 1);
incase 21:
chargeCommand(cmd_enlist, 2);
incase 22:
chargeCommand(cmd_buy, 2);
incase 23:
chargeCommand(cmd_fire, 2);
incase 24:
chargeCommand(cmd_fly, 2);
incase 25:
chargeCommand(cmd_forecast, 1);
incase 26:
chargeCommand(cmd_grant, 1);
incase 27:
cmd_headlines();
incase 28:
cmd_help();
incase 29:
cmd_ledger();
incase 30:
chargeCommand(cmd_lend, 2);
incase 31:
cmd_help();
incase 32:
chargeCommand(cmd_load, 2);
incase 33:
chargeCommand(cmd_lookout, 2);
incase 34:
chargeCommand(cmd_map, 1);
incase 35:
chargeCommand(cmd_mine, 2);
incase 36:
chargeCommand(cmd_move, 2);
incase 37:
cmd_nation();
incase 38:
chargeCommand(cmd_navigate, 2);
incase 39:
cmd_newspaper();
incase 41:
cmd_power();
incase 42:
chargeCommand(cmd_radar, 2);
incase 43:
cmd_read();
incase 44:
cmd_realm();
incase 45:
chargeCommand(cmd_repay, 2);
incase 46:
chargeCommand(cmd_route, 1);
incase 47:
chargeCommand(cmd_price, 2);
incase 48:
chargeCommand(cmd_drop, 2);
incase 49:
chargeCommand(cmd_ships, 0);
incase 50:
chargeCommand(cmd_spy, 1);
incase 51:
cmd_telegram();
incase 52:
chargeCommand(cmd_tend, 2);
incase 53:
chargeCommand(cmd_torpedo, 2);
incase 54:
chargeCommand(cmd_report, 2);
incase 56:
chargeCommand(cmd_unload, 2);
incase 57:
QuietUpdate := false;
chargeCommand(cmd_update, 1);
incase 59:
cmd_weather();
incase 60:
if UsingSerial then
writeln(Chout; "Enter message to send to system owner:");
write(Chout; "> ");
if readLine(&InputBuffer[0], INPUT_LENGTH) then
writeln();
writeln(&InputBuffer[0]);
putPrompt();
else
pretend(ioerror(Chin), void);
fi;
else
err("talking to yourself are you?");
fi;
incase 61:
incase 62:
cmd_help();
incase 63:
cmd_examine();
incase 64:
cmd_dump();
incase 65:
cmd_edit();
incase 66:
cmd_translate();
default:
writeln(Chout; "Unimplemented Empire command: ", command);
esac;
corp;
/*
* processCommands - loop, getting commands and parsing them.
*/
proc processCommands()void:
*char COMMAND_LIST =
/* 2 */ "accept\e"
/* 3 */ "assault\e"
/* 4 */ "attack\e"
/* 5 */ "board\e"
/* 6 */ "build\e"
/* 7 */ "bye\e"
/* 8 */ "census\e"
/* 9 */ "change\e"
/* 10 */ "checkpoint\e"
/* 11 */ "collect\e"
/* 12 */ "commands\e"
/* 13 */ "contract\e"
/* 14 */ "country\e"
/* 15 */ "fleet\e"
/* 16 */ "defend\e"
/* 17 */ "deliver\e"
/* 18 */ "declare\e"
/* 19 */ "designate\e"
/* 20 */ "dissolve\e"
/* 21 */ "enlist\e"
/* 22 */ "buy\e"
/* 23 */ "fire\e"
/* 24 */ "fly\e"
/* 25 */ "forecast\e"
/* 26 */ "grant\e"
/* 27 */ "headlines\e"
/* 28 */ "info\e"
/* 29 */ "ledger\e"
/* 30 */ "lend\e"
/* 31 */ "list\e"
/* 32 */ "load\e"
/* 33 */ "lookout\e"
/* 34 */ "map\e"
/* 35 */ "mine\e"
/* 36 */ "move\e"
/* 37 */ "nation\e"
/* 38 */ "navigate\e"
/* 39 */ "newspaper\e"
/* 40 */ "offer\e"
/* 41 */ "power\e"
/* 42 */ "radar\e"
/* 43 */ "read\e"
/* 44 */ "realm\e"
/* 45 */ "repay\e"
/* 46 */ "route\e"
/* 47 */ "price\e"
/* 48 */ "drop\e"
/* 49 */ "ships\e"
/* 50 */ "spy\e"
/* 51 */ "telegram\e"
/* 52 */ "tend\e"
/* 53 */ "torpedo\e"
/* 54 */ "report\e"
/* 55 */ "treaty\e"
/* 56 */ "unload\e"
/* 57 */ "update\e"
/* 58 */ "vote\e"
/* 59 */ "weather\e"
/* 60 */ "message\e"
/* 61 */ "help\e"
/* 62 */ "?\e"
/* 63 */ "examine\e"
/* 64 */ "dump\e"
/* 65 */ "edit\e"
/* 66 */ "translate\e";
*char command, p, fileName;
file() fyle;
uint cmd;
bool quit, redirected, appending;
telegramCheck();
quit := false;
while not quit do
if UsingSerial then
if WaitForChar(Input(), 0) then
writeln(Chout; "Activity on master keyboard - please wait.");
readln(&InputBuffer[0]);
if CharsEqual(&InputBuffer[0], "QUIT") then
LeaveGame := true;
writeln("Quit message sent to user.");
writeln(Chout;);
writeln(Chout;);
writeln(Chout;
"System owner requires system - please finish up.");
writeln(Chout;);
writeln(Chout;);
elif CharsEqual(&InputBuffer[0], "play") then
PlayConsole := true;
writeln("play request recorded - hang tough!!");
elif CharsEqual(&InputBuffer[0], "message") or
CharsEqual(&InputBuffer[0], "mess") then
writeln(Chout; "Message from system owner...");
write("> ");
readln(&InputBuffer[0]);
writeln(Chout; &InputBuffer[0]);
elif CharsEqual(&InputBuffer[0], "bump") then
ThisCountry*.c_timer := ThisCountry*.c_timer + 1;
elif InputBuffer[0] ~= '\e' then
writeln("Unknown command - only 'QUIT', 'play', 'message'"
" and 'bump' known.");
fi;
putPrompt();
fi;
if serialHungup() then
quit := true;
fi;
fi;
if not quit then
write(Chout; '[', ThisCountry*.c_btu, ':',
ThisCountry*.c_timer, "] Command: ");
if not readLine(&InputBuffer[0], INPUT_LENGTH) then
quit := true;
else
InputPtr := &InputBuffer[0];
skipBlanks();
command := InputPtr;
if command* ~= '\e' then
skipWord();
p := InputPtr;
skipBlanks();
p* := '\e';
redirected := false;
if InputPtr* = '>' then
InputPtr := InputPtr + 1;
redirected := true;
if InputPtr* = '>' then
InputPtr := InputPtr + 1;
appending := true;
fi;
skipBlanks();
if InputPtr* = '\e' then
err("no output file name - redirection ignored");
redirected := false;
else
fileName := InputPtr;
skipWord();
p := InputPtr;
skipBlanks();
p* := '\e';
if UsingSerial then
err("redirection disabled for remote users");
redirected := false;
elif appending then
if open(Chout, fyle, fileName) then
pretend(TextAppend(Chout), void);
else
pretend(FileCreate(fileName), void);
if not open(Chout, fyle, fileName) then
err("can't open redirection file");
redirected := false;
fi;
fi;
else
pretend(FileDestroy(fileName), void);
pretend(FileCreate(fileName), void);
if not open(Chout, fyle, fileName) then
err("can't open redirection file");
redirected := false;
fi;
fi;
fi;
fi;
QuietUpdate := true;
VerboseUpdate := false;
ContractEarnings := 0;
InterestEarnings := 0;
ImprovementCost := 0;
MilitaryCost := 0;
UtilitiesCost := 0;
cmd := lookupCommand(COMMAND_LIST, command);
if cmd = 0 then
writeln(Chout; "Unknown Empire command: ", command);
elif cmd = 1 then
writeln(Chout; "Ambiguous Empire command: ", command);
elif cmd = 7 then
/* bye */
quit := true;
else
doCommand(cmd, command);
fi;
if ContractEarnings ~= 0 then
writeln(Chout; "You earned $", ContractEarnings,
" from contracted production.");
fi;
if InterestEarnings ~= 0 then
writeln(Chout; "You earned $", InterestEarnings,
" interest from bank deposits.");
fi;
if ImprovementCost ~= 0 then
writeln(Chout; "You paid $", ImprovementCost,
" for sector improvements.");
fi;
if MilitaryCost ~= 0 then
writeln(Chout; "You paid $", MilitaryCost,
" for military supplies.");
fi;
if UtilitiesCost ~= 0 then
writeln(Chout;
"You paid $", UtilitiesCost, " for utilites.");
fi;
if redirected then
close(Chout);
open(Chout);
fi;
fi;
if updateTimer() then
/* user's timer has expired! Log him out! */
writeln(Chout; "You've run out of time! Logging out!");
quit := true;
fi;
fi;
fi;
od;
corp;